<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <meta charset="UTF-8">
    <title>首页</title>
</head>
<base href="http://${pageContext.request.serverName }:${pageContext.request.serverPort }${pageContext.request.contextPath }/"/>
<script type="text/javascript" src="jquery/jquery-2.1.1.min.js"></script>
<script type="text/javascript" src="layer/layer.js"></script>

<script type="text/javascript">
    $(function () {
        $("#btn1").click(function () {
            $.ajax({
                "url": "send/array/one.html",
                "type": "post",
                "data": {
                    "array": [5, 8, 2],
                },
                "dataType": "text",
                "success": function (response) {
                    alert(response);
                },
                "error": function (response) {
                    alert(response);
                }
            });
        })
        $("#btn2").click(function () {
            $.ajax({
                "url": "send/array/two.html",
                "type": "post",
                "data": {
                    "array[0]": 5,
                    "array[1]": 8,
                    "array[2]": 12,
                },
                "dataType": "text",
                "success": function (response) {
                    alert(response);
                },
                "error": function (response) {
                    alert(response);
                }
            });
        }),

            $("#btn3").click(function () {
                var array = [5, 8, 12];
                //var obj = {"name":"tom","age": 12};
                console.log(array.length);
                /*将字符串数组转换成JSON字符串*/
                var requestBody = JSON.stringify(array);
                console.log("转换后[空格也会算上]=" + requestBody.length);
                $.ajax({
                    "url": "send/array/three.html",
                    "type": "post",
                    "data": requestBody,
                    "contentType": "application/json;charset=UTF-8",
                    "dataType": "text",
                    "success": function (response) {
                        alert(response);
                    },
                    "error": function (response) {
                        alert(response);
                    }
                });
            })


        $("#btn4").click(function () {
            //    准备要发送的数据
            // 准备要发送的数据
            var student = {
                "stuId": 5,
                "stuName": "friend",
                "address": {
                    "province": "湖南",
                    "city": "长沙",
                    "street": "后瑞"
                },
                "subjectsList": [
                    {
                        "subjectName": "JavaSE",
                        "subjectScore": 100
                    }, {
                        "subjectName": "SSM",
                        "subjectScore": 520
                    }
                ],
                "maptwo": {
                    "k1": "v1",
                    "k2": "v2"
                }
            };


            var requestBody = JSON.stringify(student);
            //    发送AJAX请求
            $.ajax({
                "url": "send/array/object.json",
                "type": "post",
                "data": requestBody,
                "contentType": "application/json;charset=UTF-8",
                "dataType": "json",
                "success": function (response) {
                    console.log(response);
                },
                "error": function (response) {

                    alert(response);
                }
            })

        })


        $("#btn5").click(function () {
            layer.msg("Layer的弹窗")
        })
    })
</script>
<body>
<center>
    <a href="test/ssm.html">测试SSM整合环境</a><br/><br/>
    <button id="btn1">array 的方式传值</button>
    <br/><br/>
    <button id="btn2">array[x] 的方式传值</button>
    <br/><br/>
    <button id="btn3">JSON数组转换后</button>
    <br/><br/>
    <button id="btn4">用泛型接收JSON数据</button>
    <br/><br/>
    <button id="btn5">layer测试</button>
    <br/><br/>
    <a href="admin/to/main/page.html">范夕晨</a><br/><br/>
</center>
</body>
</html>
